<header class="header-container">
    <nav class="main-navigation" aria-label="主要导航菜单">
        <?php wp_nav_menu(array('theme_location' => 'primary')); ?>
    </nav>
    <div class="logo-title-container">
        <div class="logo">
            <a href="<?php echo esc_url(home_url()); ?>">
                <?php
                if (function_exists('the_custom_logo') && has_custom_logo()) {
                    the_custom_logo();
                } else {
                    ?>
                    <img src="https://wordpress12138.oss-cn-hangzhou.aliyuncs.com/wp-content/uploads/2024/05/20240501180655937.png"
                        alt="<?php bloginfo('name'); ?>" />
                    <?php
                }
                ?>
            </a>
        </div>
        <h1 class="site-title"><?php bloginfo('name'); ?></h1>
    </div>
</header>

<script>
    document.addEventListener('DOMContentLoaded', function() {
         const headerContainer = document.querySelector('.header-container');

        // 状态控制
        let isHeaderVisible = false;

        function toggleHeader(visible) {
            headerContainer.style.top = visible ? '0' : '-75px';
            isHeaderVisible = visible;
        }

        toggleHeader(false); // 初始状态隐藏header

        // 事件监听
        headerContainer.addEventListener('mouseenter', () => toggleHeader(true));
        headerContainer.addEventListener('mouseleave', () => toggleHeader(false));

        window.addEventListener('blur', () => toggleHeader(false));
        window.addEventListener('focus', () => {
            if (headerContainer.matches(':hover')) {
                toggleHeader(true);
            }
        });
    });
</script>

<style>
    .header-container {
        background: linear-gradient(90deg, rgba(255, 0, 150, 0.7), rgba(0, 204, 255, 0.7), rgba(255, 0, 150, 0.7));
        color: #ffffff;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        transition: top 0.3s ease;
        z-index: 9999;
        padding: 15px 20px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        animation: gradient 5s ease infinite;
        background-size: 300% 100%;
    }

    .header-container .logo {
        margin: 0 10px;
    }

    .header-container .logo img {
        width: 50px;
        height: auto;
    }

    .header-container h1.site-title {
        font-family: 'Orbitron', sans-serif;
        font-size: 24px;
        margin: 0 10px;
    }

    .logo-title-container {
        display: flex;
        align-items: center;
        margin-top: 10px;
    }

    .main-navigation {
        position: relative;
        z-index: 2;
    }

    .main-navigation a {
        display: inline-block;
        color: white;
        text-decoration: none;
        padding: 10px 15px;
        transition: color 0.3s ease, transform 0.3s ease;
        position: relative;
        /* 使伪元素相对 */
    }

    .main-navigation a:hover {
        color: #ffd700;
        transform: scale(1.1);
        /* 增加缩放效果 */
    }

    .main-navigation a::after {
        content: '';
        position: absolute;
        left: 50%;
        bottom: 0;
        width: 0%;
        height: 3px;
        background: white;
        transition: width 0.4s ease, left 0.4s ease;
    }

    .main-navigation a:hover::after {
        left: 0;
        width: 100%;
    }

    @keyframes gradient {
        0% {
            background-position: 0% 50%;
        }

        50% {
            background-position: 100% 50%;
        }

        100% {
            background-position: 0% 50%;
        }
    }

    .site-title {
        font-size: 2rem;
        color: white;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
    }

    @media (max-width: 768px) {
        .header-container {
            padding: 10px 15px;
            /* 调整内边距 */
        }

        .header-container h1.site-title {
            font-size: 20px;
            /* 调整标题字体大小 */
        }

        .main-navigation a {
            padding: 8px 10px;
            /* 调整导航链接的内边距 */
        }
    }
</style>